var contentPath = $("#topNavCon").attr("value");

$(function(){
    getBannerAndTitle();
    getArticleList();
    scrollCaseEvent()
});

var flag = true;   //鍔犺浇鏁版嵁鏍囧織
var totalPageIndex = 1;
/**
 * 鑷姩鍔犺浇鏁版嵁
 */
function scrollCaseEvent() {
    //鑷姩鍔犺浇鏁版嵁
    var page = 0;
    var scrollTop;     //鑾峰彇婊氬姩鏉″埌椤堕儴鐨勮窛绂�
    var scrollHeight;  //鑾峰彇鏂囨。鍖哄煙楂樺害
    var windowHeight;  //鑾峰彇婊氬姩鏉＄殑楂樺害
    $(window).scroll(function(){
        scrollTop = $(this).scrollTop();
        scrollHeight = $(document).height();
        windowHeight = $(this).height();
        if(scrollHeight - scrollTop - windowHeight < 100 && flag==true){
            getArticleList();
        }
    });
}

//鍏瘬
function getArticleList(){

    $.ajax({
        url:"getArticleList.do",
        type:"POST",
        beforeSend:function(){
            flag = false;
            $(".case-loading-gif").css("display","block");//鍙嬪ソ鎻愮ず 鍔犺浇涓�
        },
        data:{
            "firstPlateId":15,
            "secondPlateId":6,
            "pageSize":4, //涓€娆″姞杞�4鏉�
            "pageIndex":totalPageIndex
        },
        success:function(data){
            $(".case-loading-gif").css("display","none"); //鍏抽棴
            data=eval("("+data+")");
            var articleList=data.articleList;
            if(articleList.length!=null && articleList.length > 0  ){
                var html = "";
                for(var i=0; i<articleList.length; i++){
                    html += '<div class="common-case-list scroll-reveal-1">';
                    html += '<div class="case-info-contain">';
                    html += '<h4 class="info-title">'+articleList[i].title+'</h4>';
                    html += '<div class="info-text">';
                    html += '<p>';
                    var breifs = ReplaceAll(articleList[i].listBrife, "_&", "<br />");
                    html += breifs;
                    html += '</p>';
                    html += '</div>';
                    html += '<div class="info-more">';
                    html += '<a href="'+contentPath+'/pc/caseDetail/view.do?articleId='+articleList[i].articleId+'" target="_blank"><i class="transform-line"></i><span class="text">娴忚鏇村</span></a>';
                    html += '</div>';
                    html += '</div>';
                    html += '<a class="case-img-contain" href="'+contentPath+'/pc/caseDetail/view.do?articleId='+articleList[i].articleId+'" target="_blank">';
                    html += '<img src="'+articleList[i].picUrl+'" alt=""/>';
                    html += '<img src="'+articleList[i].picUrl2+'" alt=""/>';
                    html += '</a>';
                    html += '</div>';
                }
                $("#listBody").append(html);
                sr1.sync();
                flag = true;
                totalPageIndex++
            }
        },
    });
}


/**
 * 鑾峰彇澶村浘鍜� banner
 */
function getBannerAndTitle(){

    $.ajax({
        url:"getBannerAndTitle.do",
        type:"POST",
        data:{
            "other":0
        },
        success:function(data){
            data=eval("("+data+")");
            var bannerTitle=data.bannerTitle;
            if(bannerTitle != null ){
                $("#title").text(bannerTitle.pctitleh1);
                var picurl = ReplaceAll(bannerTitle.picUrl,",","");
                var url1 = 'url(' + picurl + ')';
                $("#banner").css("background-image",url1);
            }else{
                alert("缃戠粶閿欒锛岃閲嶈瘯");
            }
        },
    });
}


